<template>
  <div class="app-container">
    <div class="filter-container">
      <el-form ref="filterForm" :model="filterForm" label-position="left" label-width="0">
        <el-form-item >
            <el-radio-group v-model="filterForm.style"  @input="handleFilter">
            <el-radio-button label="0">全部</el-radio-button>
            <el-radio-button label="1">看涨</el-radio-button>
            <el-radio-button label="2">看跌</el-radio-button>
            </el-radio-group>
        </el-form-item>
        <el-form-item prop="expireDate">
       <el-radio-group v-model="filterForm.expireDate"  @input="handleFilter">
        <el-radio-button v-for="(cycle,index) in cycleList" :label="cycle.expireDate" :key="index">{{cycle.expireDate}}</el-radio-button>
      </el-radio-group>
        </el-form-item>
      </el-form>
    </div>
    <el-table
      :key="tableKey"
      v-loading="listLoading"
      :data="list"
      stripe
      border
      fit
      highlight-current-row
      style="width: 100%;"
    >
      <el-table-column label="合约" align="center" fixed="left" width="350px">
          <template slot-scope="{row}">
            <span @click="handleMarket(row)">{{ row.symbol }}</span>
          </template>
      </el-table-column>
      <el-table-column label="行权价" align="center" min-width="150px">
        <template slot-scope="{row}">
          <span>{{ row.exercise_price }}</span>
        </template>
      </el-table-column>
      <el-table-column label="类型" align="center" max-width="100px">
        <template slot-scope="{row}">
          <span v-if="row.style == 1">看涨</span>
          <span v-else>看跌</span>
        </template>
      </el-table-column>
      <el-table-column label="最新价格" align="center" min-width="150px">
        <template slot-scope="{row}">
          <span>{{ row.closePrice }}</span>
        </template>
      </el-table-column>
      <el-table-column label="上市天数" align="center" width="100px">
        <template slot-scope="{row}">
          <span>{{ row.marketDays }}</span>
        </template>
      </el-table-column>
      <el-table-column label="任务区域" align="center" width="160px">
        <template slot-scope="{row}">
          <span>{{ row.taskZone }}</span>
        </template>
      </el-table-column>
      <el-table-column label="持仓" align="center" min-width="150px">
        <template slot-scope="{row}">
          <span>{{ row.position }}</span>
        </template>
      </el-table-column>
      <el-table-column label="成交量" align="center" min-width="150px">
        <template slot-scope="{row}">
          <span>{{ row.volume }}</span>
        </template>
      </el-table-column>
      <el-table-column label="加入时间" min-width="150px">
        <template slot-scope="{row}">
          <span>{{ row.createdAt }}</span>
        </template>
      </el-table-column>
    </el-table>

    <pagination v-show="total>0" :total="total" :page.sync="filterForm.page" :limit.sync="filterForm.size" @pagination="getList" />
  </div>
</template>

<script>
//import { getFaultinessList,  removeFaultinessByID, changeFaultinessStatusByID } from '@/api/development/faultiness'
import waves from '@/directive/waves' // waves directive
import Pagination from '@/components/Pagination' // secondary package based on el-pagination
import {getOptionOptionalList} from '@/api/knowledge/option'
import {getOptionThroesList} from '@/api/knowledge/optionThroes'

export default {
  name: 'financeDashboard',
  components: { Pagination },
  directives: { waves },
  filters: {
  },
  data() {
    return {
      
      socket:"",
      tableKey: 0,
      list: null,
      windowHeight:"800",
      total: 0,
      listLoading: false,
      connected:"loading",
      cycleList:[],
      filterForm: {
        page: 1,
        size: 20,
        taskZone:-1,
        expireDate:undefined,
        style:"0",
        localSymbol: ""
      }
    }
  },
  created() {
    let symbolData = window.localStorage.getItem('localSymbol')
    symbolData = JSON.parse(symbolData)
    try {
      this.localSymbol = symbolData.code
    } catch (error) {
      
    }
    let dateHandle = new Date()
    this.filterForm.beginDate = dateHandle.getFullYear()+"-"+(dateHandle.getMonth()+1)+"-"+dateHandle.getDate()
    this.getOptionThroesList(true)
  },
  destroyed(){
  },
  methods: {
    getList:function(){
      let _this = this;
      console.log("期权",_this.filterForm)
      getOptionOptionalList(_this.filterForm).then((response) => {
        console.log("getOptionOptionalList",response)
          if (response.code === 200) {
            this.list = response.data.list
            this.total = response.data.total
          } else {
            _this.$message({
              message: response.msg,
              type: 'error'
            })
          }
      })
    },
    getOptionThroesList:function(loadOption=false){
      let _this = this;
      getOptionThroesList({
        "size":12
      }).then((response) => {
        console.log("getOptionThroesList",response)
          if (response.code === 200) {
            _this.cycleList = response.data.list
            if(loadOption){
              _this.filterForm.expireDate = _this.cycleList[0].expireDate
              _this.getList()
            }
          } else {
            _this.$message({
              message: response.msg,
              type: 'error'
            })
          }
      })
    },
    handleMarket:function(row){
      this.$router.push({ path:'/quotation/quotation', query: {"symbol":row.symbol} })
    },
    handleFilter() {
      this.filterForm.page = 1
      this.getList()
    }
  }
}
</script>
<style>
</style>